<?php defined('SYSPATH') or die('No direct script access.');

class Controller_BoDishItem extends Controller_BoBase {
	public $auth_required = TRUE;
	protected $modelName = "dishItem";

	public function action_index()
	{
		$this->request->response = $this->baseInfoView("home",$this->modelName);
	}

	public function action_insertOrUpdatePage(){
		$view = View::factory("pages/bo/dishItem/dish_item_edit_page");
		$view->model = null;
		if (array_key_exists("dishitemid", $_REQUEST) && !empty($_REQUEST["dishitemid"])){
			$model = ORM::factory($this->modelName,$_REQUEST["dishitemid"]);
			$view->model = $model;
		}
		exit($view->render());
	}

	public function action_insertOrUpdate(){
		if (array_key_exists("id", $_REQUEST)){
			$model = ORM::factory($this->modelName,$_REQUEST["id"]);
			$model->update($_REQUEST);
		}else{
			ORM::factory($this->modelName)->insert($_REQUEST);
		}
		//show dish result
		$dish_cate_id = $_REQUEST["dishcateid"];
		$dish = ORM::factory("dish");
		$result_dish = $dish->where("dish_cate_id","=",$dish_cate_id)->and_where("status","<>","I")->find_all();
		$view = View::factory("pages/bo/dish_page");
		$view->result_dish = $result_dish;
		$dish_category = ORM::factory("dishCategory",$dish_cate_id);
		$view->result_supplier_name = ORM::factory("supplier",$dish_category->supplierid)->name;
		$view->result_dish_cate_name = $dish_category->name;
		exit($view->render());
	}

	public function action_show(){
		exit($this->baseInfoView("member/member_page",$this->modelName)->render());
	}
	
	public function action_deleteAll(){
		if(ORM::factory($this->modelName)->deleteAll($_POST["ids"])){
			$view = View::factory("pages/bo/common/message_dialog");
			$view->message = "删除成功";
			exit($view->render());
		}
	}
}
